package cn.ffcs.businessrequest.web;


import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionContext;

import cn.ffcs.base.web.BaseAction;
import cn.ffcs.base.web.PageControl;
import cn.ffcs.businessrequest.model.ProdAdvReq;
import cn.ffcs.businessrequest.model.ReqDocu;
import cn.ffcs.businessrequest.service.IProdAdvReqService;
import cn.ffcs.businessrequest.service.IReqDocuService;
import cn.ffcs.businessrequest.service.ProdAdvReqService;
import cn.ffcs.organ.model.OrgRelaPerson;
import cn.ffcs.organ.model.Organization;
import cn.ffcs.organ.model.Person;
import cn.ffcs.organ.service.IOrgRelaPersonService;
import cn.ffcs.security.model.User;
import cn.ffcs.security.model.UserResource;
import cn.ffcs.system.dict.model.Dict;
import cn.ffcs.system.dict.model.DictType;
import cn.ffcs.system.dict.service.DictService;
import cn.ffcs.system.dict.service.DictTypeService;
import cn.ffcs.util.MyList;
import cn.ffcs.util.context.ApplicationContextUtil;
import cn.ffcs.util.converter.DateConverter;

/**
 * 
 * 业务需求交互单action层，实现页面业务逻辑<br/> <table>
 * <tr>
 * <td>负责人/principal: </td>
 * <td colspan="2">pany</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr> 
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author pany
 * @version $Id$
 */
public class ProdAdvReqAction<P extends ProdAdvReq> extends BaseAction<P>
{

    private static final int BUFFER_SIZE = 512 * 1024;
    /** 业务POJO **/
    private P prodAdvReq;
    /** 附件上传 **/
    private List<File> uploads;
    /** 上传附件名称 **/
    private List<String> fileNames;
    /** 新产品需求服务 **/
    private ProdAdvReqService prodAdvReqService;
    /** 文档服务 **/
    private IReqDocuService reqDocuService;
    /** 上传附件名称 **/
    private IOrgRelaPersonService orgRelaPersonService;
    /** 需求文档 **/
    private List<ReqDocu> reqDocus;
    /** 组织人员关系对象 **/
    private OrgRelaPerson orgRelaPerson;
    /** 提交标示 **/
    private String flag;
    /** 需求单 **/
    private List<P> prodAdvReqs;
    /** 数据字典类型服务 **/
    private DictTypeService dictTypeService;
    /** 数据字典服务 **/
    private DictService dictService;
    /** 需求类型 **/
    private List<Dict> types;
    /** 重要性 **/
    private List<Dict> importances;
    
    /** 合并的原需求单id **/
    private String refIds;
    /** 分解的原需求单id **/
    private String oldProdAdvReqId;
    /** 已分解的需求单 **/
    private List<P> newProdAdvReqs;
    /** 分解的原需求单id **/
    private String reclaim;
    /** 办理意见 **/
    private String advice;
    
    
    /**
     * 
     * 初始化字典数据
     * @return
     */
    @SuppressWarnings("unchecked")
    public void initDict(){
        String reqProdtypes = "REQ_PROD_TYPE";
        String reqImportType = "REQ_IMPORT_TYPE";
        Criterion cond = Restrictions.eq("keyValue", reqImportType );
        Criterion cond1 = Restrictions.eq("keyValue",  reqProdtypes );
        List dictType = dictTypeService.findBy(cond);
        List dictType1 = dictTypeService.findBy(cond1);
        //重要性
        if (dictType != null && dictType.size() > 0)
        {
            for (int i = 0; i < dictType.size(); i++)
            {
                Criterion dtcond = Restrictions.eq("dictType.id",
                        ((DictType) dictType.get(i)).getId());
                    importances = (List<Dict>) dictService.findBy(dtcond);
            }
        }
        //需求类型
        if (dictType1 != null && dictType1.size() > 0)
        {
            for (int i = 0; i < dictType1.size(); i++)
            {
                Criterion dtcond = Restrictions.eq("dictType.id",
                        ((DictType) dictType1.get(i)).getId());
                types = (List<Dict>) dictService.findBy(dtcond);
            }
        }
    }
    
    /**
     * 初始化业务数据
     * @return
     */
    @SuppressWarnings("unchecked")
    public String init(){
        if (prodAdvReq!=null){
            Criterion cond1 = Restrictions.eq("refEntity", prodAdvReq.getClass().getName());
            Criterion cond2 = Restrictions.eq("refEntityId", prodAdvReq.getId().toString());
            Criterion condAttach = Restrictions.and(cond1, cond2);
            reqDocus=reqDocuService.findBy(condAttach);
        }
        initDict();
        return SUCCESS;
    }
    
    public Organization getOrgByPerson(Person person ){
        if (prodAdvReq!=null&&person!=null&&person.getId()>0){
            return orgRelaPersonService.findByPageByPersonId(person.getId()+"");
        }
        return null;
    }
    
    /**
     * 保存操作：
     * 保存业务和流程数据信息
     * @return
     */
    public String saveOrUpdate()
    {
        // 获取附件是否为发布
        String[] attachIDs = getContextObjects("attachIDs");
        // 获取附件类型
        String [] fileTypes = getContextObjects("filetype");
        // 删除附件
        String[] delIDs = getContextObjects("delIDs");
        String oper="";
        String curStatus="";
       // 保存产品资料数据
        if(prodAdvReq!=null){
            if(prodAdvReq.getReqCode()==null||"".equals(prodAdvReq.getReqCode())){
                prodAdvReq.setReqCode(getReqCode());
            }
            
            if("".equals(flag)&&"".equals(prodAdvReq.getTranStatus())){
                oper="保存";
                prodAdvReq.setTranStatus("NEW");
            }else if("WAIT".equals(flag)){
                curStatus=prodAdvReq.getTranStatus();
                prodAdvReq.setTranStatus("WAIT");
                oper="提交";
            }else if("REFUSE".equals(flag)&&("PENDING".equals(prodAdvReq.getTranStatus())||"WAIT".equals(prodAdvReq.getTranStatus()))){
                prodAdvReq=baseService.findById(prodAdvReq.getId());
                if(!prodAdvReq.getTranStatus().equals("WAIT")&&!prodAdvReq.getTranStatus().equals("PENDING")){
                    returnMsg="当前状态不能执行此操作，操作失败！";
                    return "failure";
                }
                prodAdvReq.setTranStatus("REFUSE");
                oper="拒绝";
            }else if("PENDING".equals(flag)&&("PENDING".equals(prodAdvReq.getTranStatus())||"WAIT".equals(prodAdvReq.getTranStatus()))){
                prodAdvReq=baseService.findById(prodAdvReq.getId());
                if(!prodAdvReq.getTranStatus().equals("WAIT")){
                    returnMsg="当前状态不能执行此操作，操作失败！";
                    return "failure";
                }
                prodAdvReq.setTranStatus("PENDING");
                oper="接收";
            }else if("PASS".equals(flag)&&"PENDING".equals(prodAdvReq.getTranStatus())){
                ////判断审核结论：true：审核通过；false：不通过
                String result=this.getContextObject("result");
                if("true".equals(result)){
                    curStatus=prodAdvReq.getTranStatus();
                    prodAdvReq.setTranStatus("PASS");
                    oper="审核通过";
                }else{
                    prodAdvReq.setTranStatus("PROD");
                    oper="审核不通过";
                }
            }else if("PROD".equals(flag)&&"WAIT".equals(prodAdvReq.getTranStatus())){
                prodAdvReq.setTranStatus("PROD");
                oper="启动";
            }
            if(prodAdvReq.getStartPerson()!=null&&prodAdvReq.getStartPerson().getId()!=null){
                prodAdvReq.setStartDept(getOrgByPerson(prodAdvReq.getStartPerson()));
            }else{
                User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
                if(curUser!=null&&curUser.getPerson()!=null){
                    prodAdvReq.setStartPerson(curUser.getPerson());
                    prodAdvReq.setStartDept(getOrgByPerson(prodAdvReq.getStartPerson()));
                }
            }
            if(prodAdvReq.getProdPerson()!=null&&prodAdvReq.getProdPerson().getId()!=null){
                prodAdvReq.setProdDept(getOrgByPerson(prodAdvReq.getProdPerson()));
            }else{
                prodAdvReq.setProdPerson(null);
                prodAdvReq.setProdDept(null);
            }

            prodAdvReqService.saveProdAdvReq(prodAdvReq,uploads, fileNames, fileTypes, delIDs);

            if(oper.equals("提交")||"审核通过".equals(oper)){
                Criterion cond1 = Restrictions.eq("refEntity", prodAdvReq
                        .getClass().getName());
                Criterion cond2 = Restrictions.eq("refEntityId", prodAdvReq.getId()
                        + "");
                Criterion cond3 = Restrictions.isNotNull("docType");
                Criterion cond4 = Restrictions.and(cond1, cond2);
                Criterion cond6 = Restrictions.and(cond4, cond3);
                List<ReqDocu> reqDocus = reqDocuService.findBy(cond6);
                boolean flag=true;
                if("提交".equals(oper)){
                    for(ReqDocu docu:reqDocus){
                        if("CPGJXQSMS".equals(docu.getDocType().getKeyValue())){
                            flag=false;
                        }
                    }
                }
                if("审核通过".equals(oper)){
                    for(ReqDocu docu:reqDocus){
                        if("XQPSJY".equals(docu.getDocType().getKeyValue())){
                            flag=false;
                        }
                    }
                }
                if (flag)
                {
                    if(curStatus==null||"".equals(curStatus))
                        curStatus="NEW";
                    prodAdvReq.setTranStatus(curStatus);
                    prodAdvReqService.saveOrUpdate(prodAdvReq);
                    this.returnMsg = "操作失败！要求提交附件不完整，不允许提交!";
                    this.returnUrl = null;
                    return "failure";
                }
            }
            
            if (!oper.equals("保存") && !"".equals(oper))
            {
                DateConverter dateConverter=new DateConverter();
                prodAdvReq.appendTranReason(ApplicationContextUtil
                        .getUserContextObject().getCurrUser().getPerson()
                        .getName(), oper,dateConverter.convertValue(null,baseService.getCurrSysdate(),String.class)+"", advice);
            }
            prodAdvReqService.saveOrUpdate(prodAdvReq);
            
            ///审核通过成功，跳转成功页面，提示是否启动流程
            if("审核通过".equals(oper)){
                return "startup";
            }
            
        }
        //初始化数据
        findById();
        //流程初始化
        return SUCCESS;
    }

    public String refuse(){
        if (prodAdvReq != null && prodAdvReq.getId() > 0)
        {
            prodAdvReq=(P)prodAdvReqService.findById(prodAdvReq.getId());
            if("WAIT".equals(prodAdvReq.getTranStatus())){
                prodAdvReq.setTranStatus("REFUSE");

                DateConverter dateConverter=new DateConverter();
                prodAdvReq.appendTranReason(ApplicationContextUtil
                        .getUserContextObject().getCurrUser().getPerson()
                        .getName(), "回退需求单",dateConverter.convertValue(null,baseService.getCurrSysdate(),String.class)+"", advice);
                
                prodAdvReqService.saveOrUpdate(prodAdvReq);
            }
            else{
                returnMsg="当前状态不能执行此操作，操作失败！";
                return "failure";
            }
        }
        return SUCCESS;
    }
    
    public String reclaimProdAdvReq(){
        if (prodAdvReq != null && prodAdvReq.getId() > 0)
        {
            prodAdvReq=(P)prodAdvReqService.findById(prodAdvReq.getId());
            if("WAIT".equals(prodAdvReq.getTranStatus())){
                prodAdvReq.setTranStatus("NEW");
                prodAdvReq.setTranReason("");
                prodAdvReqService.saveOrUpdate(prodAdvReq);
            }else{
                returnMsg="当前状态不能执行此操作，操作失败！";
                return "failure";
            }
        }
        findByPage();
        return SUCCESS;
    }
    
    public String setNextStatu(String curStatu){
        if(curStatu==null)
            curStatu="";
        Map map=new HashMap();
        map.put("", "NEW");
        map.put("NEW", "WAIT");
        map.put("WAIT", "PROD");
        map.put("PROD", "PROD");
        return map.get(curStatu)+"";
    }
    
    public String findById()
    {
        //业务数据初始化
        init();
        if (prodAdvReq != null && prodAdvReq.getId() != 0)
        {
            prodAdvReq = (P) baseService.findById(prodAdvReq.getId());
            if("PENDING".equals(prodAdvReq.getTranStatus())){
                return "pending";
            }
        }else{
            prodAdvReq=(P)new ProdAdvReq();
            
            User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
            if(curUser!=null&&curUser.getPerson()!=null){
                prodAdvReq.setStartPerson(curUser.getPerson());
                prodAdvReq.setStartDept(getOrgByPerson(prodAdvReq.getStartPerson()));
            }
            prodAdvReq.setBegin(baseService.getCurrSysdate());
        }
        return SUCCESS;
    }
    
    /**
     * 获取分页数据
     * @return
     */
    @SuppressWarnings("unchecked")
    public String findByPage()
    {
        //如果第一次装置，默认参数
        if (pageControl == null)
        {
            pageControl = new PageControl();
        }
        User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
        HashMap<String, Object> conds=super.getConds();
        
        ///判断有权限的，显示所有提交单；否则，显示本人相关单
        List<UserResource> modelMenus = ApplicationContextUtil.getUserContextObject().getUserResources();
        boolean searchAll = false;
        for (UserResource ur : modelMenus)
        {
            if (ur.getKey().equals("OBJ_ADV_REQ_MAN"))
            {
                searchAll = true;
                break;
            }
        }
        if(conds==null)
            conds=new HashMap();
        if(searchAll){  //管理员权限
            conds.put("ADMIN", curUser.getPerson());
//          WAIT:等待处理，REFUSE:拒绝，PENDING:待审核，PASS:审核通过
          super.setConds(conds);
          
          pageControl = baseService.findByPage(combineCond(), pageControl.getPageNo(),
                  pageControl.getPageSize());
          return "admin";
        }else{
            if(curUser!=null&&curUser.getPerson()!=null){
                conds.put("startPerson", curUser.getPerson());
            }
            super.setConds(conds);
            pageControl = baseService.findByPage(combineCond(), pageControl.getPageNo(),
                    pageControl.getPageSize());
            return SUCCESS;
        }
    }
    
    /**
     * 管理员页面
     */
    public String findByAdminPage(){
        //如果第一次装置，默认参数
        if (pageControl == null)
        {
            pageControl = new PageControl();
        }
        User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
        HashMap<String, Object> conds=super.getConds();
        if(conds==null)
            conds=new HashMap();
        conds.put("ADMIN", "");
//        WAIT:等待处理，REFUSE:拒绝，PENDING:待审核，PASS:审核通过
        super.setConds(conds);
        
        pageControl = baseService.findByPage(combineCond(), pageControl.getPageNo(),
                pageControl.getPageSize());
        return SUCCESS;
    }
    
    /**
     * 查看操作
     */
    public String lookProdAdvReq()
    {
        this.findById();
//        if(prodAdvReq!=null&&prodAdvReq.getStartPerson()!=null){
//            if(ApplicationContextUtil.getUserContextObject().getCurrUser().getPersonID().equals(prodAdvReq.getStartPerson().getId()+"")){
//                reclaim="reclaim";  //本人的单则可以回收，否则接收
//            }
//        }
        ///判断有权限的，显示所有提交单；否则，显示本人相关单
        List<UserResource> modelMenus = ApplicationContextUtil.getUserContextObject().getUserResources();
        for (UserResource ur : modelMenus)
        {
            if (ur.getKey().equals("OBJ_ADV_REQ_MAN"))
            {
                reclaim="reclaim";
                break;
            }
        }
        
        return SUCCESS;
    }
    
    /**
     * 删除操作
     */
    public String remove()
    {
        baseService.remove(prodAdvReq);
        return SUCCESS;
    }

    /**
     * 转入合并需求单
     */
    public String listMergeDemand()
    {
        return SUCCESS;
    }
    
    /**
     * 查询所有需求单
     */
    public String viewProdAdvReq()
    {
        ActionContext ctx = ActionContext.getContext();
        HttpServletResponse response = (HttpServletResponse) ctx
                .get(ServletActionContext.HTTP_RESPONSE);
        try
        {
            HashMap<String, Object> oldConds = super.getConds();
            HashMap<String, Object> newConds = new HashMap();
            ///合并需求单：必须是未被合并或分解过的审核通过的需求单，才允许合并
            if (oldConds != null)
            {
                Iterator i = oldConds.entrySet().iterator();
                while (i.hasNext())
                {
                    Entry entry = (Entry) i.next();
                    String key = (String) entry.getKey();
                    if (oldConds.get(key) != null)
                    {
                        String str = oldConds.get(key).toString();
                        str = new String(str.getBytes("iso8859-1"), "utf-8");
                        if (str != null && !str.equals(""))
                        {
                            newConds.put(key, str);
                        }
                    }
                }
            }
            newConds.put("HEBING", "1");
            newConds.put("tranStatus", "PASS");//2.2跟yejq确认：查询所有审核通过的需求单，才能进行合并、分解
            
            super.setConds(newConds);
            prodAdvReqs = baseService.findBy(combineCond());
            String xml = MyList.getAll(prodAdvReqs);
            response.setCharacterEncoding("gb2312");// 页面编码设置
            response.setContentType("text/xml");// 页面文件头格式
            response.getWriter().write(xml);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 进入合并需求单页面
     */
    public String toAuditProdAdvReq(){
        String [] refId=refIds.split(",");
        String reqCode="";
        String startPerson="";
        try{
            List<ReqDocu> tmp; 
            prodAdvReqs=new ArrayList<P>();
            if (refId.length > 0)
                for(int i=0;i<refId.length;i++){
                    int k=new Integer(refId[i]);
                    if (k>0){
                        prodAdvReq=baseService.findById(k);
                        reqCode+=","+prodAdvReq.getReqCode();
                        startPerson+=","+prodAdvReq.getStartDept().getName()+":"+prodAdvReq.getStartPerson().getName();
                        prodAdvReqs.add(prodAdvReq);
                        Criterion cond1 = Restrictions.eq("refEntity",new ProdAdvReq().getClass().getName());
                        Criterion cond2 = Restrictions.eq("refEntityId", k+"");
                        Criterion condAttach = Restrictions.and(cond1, cond2);
                        tmp=reqDocuService.findBy(condAttach);
                        if(reqDocus==null){
                            reqDocus=tmp;
                        }else{
                            reqDocus.addAll(tmp);
                        }
                    }
                }
                {
                    reqCode = reqCode.substring(1);
                    startPerson = startPerson.substring(1);
                    prodAdvReq.setReqCode(reqCode);
                    DateConverter dateConverter=new DateConverter();
                    prodAdvReq.appendTranReason(ApplicationContextUtil
                            .getUserContextObject().getCurrUser().getPerson()
                            .getName(), "合并需求单",dateConverter.convertValue(null,baseService.getCurrSysdate(),String.class)+"", "发起人："+startPerson);
                }
        }
        catch(Exception e){
            this.returnMsg="合并需求单异常："+e.getMessage();
            return "failure";
        }
        initDict();
        return SUCCESS;
    }
    
    /**
     * 合并需求单
     * TODO 请输入方法说明
     * @return
     */
    public String auditProdAdvReq(){
        //合并需求单：新增需求单，修改原需求单为合并状态，复制一份附件
        if(prodAdvReq!=null){
            if(refIds!=null){
                String [] objs=refIds.split(",");
                if(objs.length>1){
                    if(prodAdvReq.getStartPerson()!=null&&prodAdvReq.getStartPerson().getId()!=null){
                        prodAdvReq.setStartDept(getOrgByPerson(prodAdvReq.getStartPerson()));
                    }else{
                        User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
                        if(curUser!=null&&curUser.getPerson()!=null){
                            prodAdvReq.setStartPerson(curUser.getPerson());
                            prodAdvReq.setStartDept(getOrgByPerson(prodAdvReq.getStartPerson()));
                        }
                    }
                    if(prodAdvReq.getProdPerson()!=null&&prodAdvReq.getProdPerson().getId()!=null){
                        prodAdvReq.setProdDept(getOrgByPerson(prodAdvReq.getProdPerson()));
                    }else{
                        prodAdvReq.setProdPerson(null);
                        prodAdvReq.setProdDept(null);
                    }
                    prodAdvReq.setOpType("HB");
                    prodAdvReq.setChildAreq("");
                    prodAdvReq.setTranStatus("PASS");
                    prodAdvReqService.saveProdAdvReq(prodAdvReq,objs);
                }
            }
        }
        return SUCCESS;
    }
    
    /**
     * 选择分解需求单
     * TODO 请输入方法说明
     * @return
     */
    public String listResolveDemand(){
        //如果第一次装置，默认参数
        if (pageControl == null)
        {
            pageControl = new PageControl();
        }
        User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
        HashMap<String, Object> conds=super.getConds();
        ///分解需求单：必须是未被合并或分解过的审核通过的需求单，才允许分解
        if(conds==null)
            conds=new HashMap();
        conds.put("tranStatus", "PASS");
        conds.put("FENJIE", "1");
        super.setConds(conds);
        pageControl = baseService.findByPage(combineCond(), pageControl.getPageNo(),
                pageControl.getPageSize());
        return SUCCESS;
    }
    
    /**
     * 分解需求单
     * TODO 请输入方法说明
     * @return
     */
    public String toResolveDemand(){
        if (prodAdvReq != null && prodAdvReq.getId() != 0)
        {
            prodAdvReq = (P) baseService.findById(prodAdvReq.getId());
            if(refIds!=null&&!"".equals(refIds)){
                String []arr=refIds.split(",");
                newProdAdvReqs=new ArrayList<P>();
                for(String tmp:arr){
                    P obj = (P) baseService.findById(new Integer(tmp));
                    newProdAdvReqs.add(obj);
                }
            }
        }
        initDict();
        return SUCCESS;
    }

    /**
     * 分解需求单
     * TODO 请输入方法说明
     * @return
     */
    public String resolveDemand(){
        if (oldProdAdvReqId != null && !"".equals(oldProdAdvReqId))
        {
            if(prodAdvReq.getStartPerson()!=null&&prodAdvReq.getStartPerson().getId()!=null){
                prodAdvReq.setStartDept(getOrgByPerson(prodAdvReq.getStartPerson()));
            }else{
                User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
                if(curUser!=null&&curUser.getPerson()!=null){
                    prodAdvReq.setStartPerson(curUser.getPerson());
                    prodAdvReq.setStartDept(getOrgByPerson(prodAdvReq.getStartPerson()));
                }
            }
            if(prodAdvReq.getProdPerson()!=null&&prodAdvReq.getProdPerson().getId()!=null){
                prodAdvReq.setProdDept(getOrgByPerson(prodAdvReq.getProdPerson()));
            }else{
                prodAdvReq.setProdPerson(null);
                prodAdvReq.setProdDept(null);
            }
            prodAdvReqService.saveProdAdvReq(prodAdvReq,oldProdAdvReqId);
            if(refIds==null||refIds.equals("")){
                refIds=prodAdvReq.getId()+"";
            }else{
                refIds=refIds+","+prodAdvReq.getId();
            }
        }
        return SUCCESS;
    }
    
    /**
     * 组合查询条件
     * @return
     */
    public Criterion combineCond()
    {
        Criterion cond = null;
        if (super.getConds() != null)
        {
            // 遍历参数表
            Iterator i = super.getConds().entrySet().iterator();
            while (i.hasNext())
            {
                Entry entry = (Entry) i.next();
                String key = (String) entry.getKey();
                if (super.getConds().get(key) != null
                        && !StringUtils.isEmpty(super.getConds().get(key)
                                .toString()))
                {
                    // 根据实际情况做处理
                    Criterion temp = null;
                    if (key.equalsIgnoreCase("name"))
                    {
                        temp = Restrictions.like(key, "%"
                                + super.getConds().get(key).toString() + "%");
                    }else if(key.equalsIgnoreCase("ADMIN")){
                        temp=Restrictions.or(Restrictions.eq("tranStatus","WAIT"),Restrictions.eq("tranStatus","PENDING"));
                        temp=Restrictions.or(temp,Restrictions.eq("tranStatus","PASS"));
                        temp=Restrictions.or(temp,Restrictions.eq("startPerson",super.getConds().get(key)));
                    }else if(key.equalsIgnoreCase("HEBING")){
                        temp = Restrictions.isNull("childAreq");
                        temp = Restrictions.isNull("opType");
                    }else if(key.equalsIgnoreCase("FENJIE")){
                        temp = Restrictions.isNull("childAreq");
                        temp = Restrictions.isNull("opType");
                    }
                    else
                    {
                        temp = Restrictions.eq(key, super.getConds().get(key));
                    }

                    if (cond == null)
                    {
                        cond = temp;
                    }
                    else
                    {
                        cond = Restrictions.and(cond, temp);
                    }
                }
            }
        }
        return cond;
    }

    /**
     * 获取需求编号操作
     * @return
     */
    public String getReqCode()
    {
        String nextval= baseService.getNextval("seq_req_num");
        return "FJ"+nextval;
    }

    /**
     * 获取需求编号操作
     * @return
     */
    public String inputMessage()
    {
        return SUCCESS;
    }
    
    
    public List<File> getUpload()
    {
        return uploads;
    }

    public void setUpload(List<File> uploads)
    {
        this.uploads = uploads;
    }
    
    public List<String> getUploadFileName()
    {
        return fileNames;
    }

    public void setUploadFileName(List<String> fileNames)
    {
        this.fileNames = fileNames;
    }
    
    public List<ReqDocu> getReqDocus()
    {
        return reqDocus;
    }

    public void setReqDocus(List<ReqDocu> reqDocus)
    {
        this.reqDocus = reqDocus;
    }

    public IOrgRelaPersonService getOrgRelaPersonService()
    {
        return orgRelaPersonService;
    }

    public void setOrgRelaPersonService(IOrgRelaPersonService orgRelaPersonService)
    {
        this.orgRelaPersonService = orgRelaPersonService;
    }

    public OrgRelaPerson getOrgRelaPerson()
    {
        return orgRelaPerson;
    }

    public void setOrgRelaPerson(OrgRelaPerson orgRelaPerson)
    {
        this.orgRelaPerson = orgRelaPerson;
    }

    public P getprodAdvReq()
    {
        return prodAdvReq;
    }

    public void setprodAdvReq(P prodAdvReq)
    {
        this.prodAdvReq = prodAdvReq;
    }

    public IReqDocuService getReqDocuService()
    {
        return reqDocuService;
    }

    public void setReqDocuService(IReqDocuService reqDocuService)
    {
        this.reqDocuService = reqDocuService;
    }

    public P getProdAdvReq()
    {
        return prodAdvReq;
    }

    public void setProdAdvReq(P prodAdvReq)
    {
        this.prodAdvReq = prodAdvReq;
    }

    public String getFlag()
    {
        return flag;
    }

    public void setFlag(String flag)
    {
        this.flag = flag;
    }

    public List<P> getProdAdvReqs()
    {
        return prodAdvReqs;
    }

    public void setProdAdvReqs(List<P> prodAdvReqs)
    {
        this.prodAdvReqs = prodAdvReqs;
    }

    public String getRefIds()
    {
        return refIds;
    }

    public void setRefIds(String refIds)
    {
        this.refIds = refIds;
    }

    public String getOldProdAdvReqId()
    {
        return oldProdAdvReqId;
    }

    public void setOldProdAdvReqId(String oldProdAdvReqId)
    {
        this.oldProdAdvReqId = oldProdAdvReqId;
    }

    public List<P> getNewProdAdvReqs()
    {
        return newProdAdvReqs;
    }

    public void setNewProdAdvReqs(List<P> newProdAdvReqs)
    {
        this.newProdAdvReqs = newProdAdvReqs;
    }

    public DictService getDictService()
    {
        return dictService;
    }

    public void setDictService(DictService dictService)
    {
        this.dictService = dictService;
    }

    public DictTypeService getDictTypeService()
    {
        return dictTypeService;
    }

    public void setDictTypeService(DictTypeService dictTypeService)
    {
        this.dictTypeService = dictTypeService;
    }

    public List<Dict> getImportances()
    {
        return importances;
    }

    public void setImportances(List<Dict> importances)
    {
        this.importances = importances;
    }

    public List<Dict> getTypes()
    {
        return types;
    }

    public void setTypes(List<Dict> types)
    {
        this.types = types;
    }

    public String getReclaim()
    {
        return reclaim;
    }

    public void setReclaim(String reclaim)
    {
        this.reclaim = reclaim;
    }

    public ProdAdvReqService getProdAdvReqService()
    {
        return prodAdvReqService;
    }

    public void setProdAdvReqService(ProdAdvReqService prodAdvReqService)
    {
        this.prodAdvReqService = prodAdvReqService;
    }

    public String getAdvice()
    {
        return advice;
    }

    public void setAdvice(String advice)
    {
        this.advice = advice;
    }

    
}
